#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

#define N 10

typedef void (*callback_t)();

void Worker()
{
  int cnt = 10;
  while(cnt)
  {
    printf("I am child process, pid: %d, ppid: %d, cnt: %d\n", getpid(), getppid(), cnt);

    sleep(1);
    cnt--;
  }
}

void createSubPorcess(int n, callback_t cb)
{
  int i = 0;
  for(i = 0; i < n; i++)
  {
    sleep(1);
    pid_t id = fork();
    if(id == 0)
    {
      printf("create child process success: %d\n", i);
      cb();
      exit(0);
    }
  }
}


int main()
{
  createSubPorcess(N, Worker);
  sleep(100);
  return 0;

}
  
